function choice = customAgent(playerName,round,playerIndx,results,roster,rankings)

oldRankings = rankings;
rankings = loadCustomRankings(playerName,oldRankings);

if isempty(rankings)
    fprintf('(just greedy): ');
    choice = greedyAgent(round,playerIndx,results,roster,oldRankings);
    return;
end

[value vIndx] = sort(rankings.rank,'descend');
for i=1:length(vIndx)
    if rankings.available(vIndx(i)) && ....
            ~positionFull(rankings,vIndx(i),roster,results,playerIndx,1)
        choice = rankings.id(vIndx(i));
        fprintf('%d - %d (%d)\n',round,playerIndx,i);
        return;
    end
end
%should not get here, but if so, be greedy
fprintf('  UH-OH, default to greedy:\n  ');
choice = greedyAgent(round,playerIndx,results,roster,oldRankings);

end

function customRankings = loadCustomRankings(playerName,rankings)

customRankings = parseRankings(strcat(playerName,'.csv'));
if isempty(customRankings)
    return;
end
available = zeros(size(rankings.available));
for i=1:length(customRankings.id)
   rIndx = rankings.id == customRankings.id(i);
   available(i) = rankings.available(rIndx);
end
customRankings.available = available;
end
